package elcs.point.model;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Repository;

import elcs.board.model.ListVO;
import elcs.board.model.PagingBean;
import elcs.member.model.MemberDao;
import elcs.member.model.MemberVO;
@Repository
public class TradePointServiceImpl implements TradePointService{
	@Resource(name="tradePointDaoImpl")
	private TradePointDao tradePointDao;
	@Resource(name="memberDaoImpl")
	private MemberDao memberDao;
	
	
	@Override
	public void minusPoint(HttpSession session, String content) {
		// TODO Auto-generated method stub
		System.out.println("minusPoint");
		MemberVO mvo=(MemberVO)session.getAttribute("mvo");
		TradePointVO tpVO=new TradePointVO(content,0,1000,mvo.getId());
		tradePointDao.register(tpVO);
		mvo.setPoint(mvo.getPoint()-1000);
		memberDao.updateMemberByPoint(mvo);
		
	}


	@Override
	public ListVO mypagePointList(Map map) throws Exception {
		// TODO Auto-generated method stub
		
		String pageNo=(String) map.get("pageNo");
		if(pageNo==null||pageNo==""){ 
			pageNo="1";
		map.put("pageNo", pageNo);
		
		
		}
		List<TradePointVO> list= tradePointDao.mypagePointList(map) ;
		int total=this.tradePointDao.getTotalContent(map);
		
		PagingBean paging=new PagingBean(total, Integer.parseInt(pageNo));
		ListVO lvo=new ListVO(list,paging);
		
		
		return lvo;
	}

}
